package cn.yeziji.forum.controller;

import cn.yeziji.forum.common.ForumResult;
import cn.yeziji.forum.dao.intf.ForumUserSettingsDao;
import cn.yeziji.forum.dto.user.ForumUserDTO;
import cn.yeziji.forum.utils.ForumResultUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 用户配置控制器
 *
 * @author gzkemays
 * @since 2022/4/7 10:12
 */
@RestController
@RequestMapping("/settings")
public class ForumUserSettingsController {
  @Resource ForumUserSettingsDao userSettingsDao;

  @PostMapping("/user")
  public ForumResult getUserSettings(@RequestBody ForumUserDTO dto) {
    String nickname = dto.getNickname();
    if (nickname == null) {
      return ForumResultUtils.ok(userSettingsDao.getUserSettings());
    } else {
      return ForumResultUtils.ok(userSettingsDao.getUserSettingsByNickname(nickname));
    }
  }
}
